import request from "@/request";
import website from "@/config/website";

export const reqGet = (data) =>
  request({
    url: "/admin-api/system/captcha/get",
    method: "post",
    data,
  });

export const reqCheck = (data) =>
  request({
    url: "/admin-api/system/captcha/check",
    method: "post",
    data,
  });

export const getTenantIdByName = (name) =>
  request({
    url: "/system/tenant/get-id-by-name",
    method: "get",
    params: {
      name,
    },
  });

export const loginByUsername = (username, password, captchaVerification) =>
  request({
    url: "/admin-api/system/auth/login",
    method: "post",
    data: {
      username,
      password,
      captchaVerification,
    },
  });

export const getUser = (id) => {
  return request({
    url: "/api/trio-system/user/mes/detail",
    method: "post",
    data: {
      id,
    },
  });
};

export const getButtons = () =>
  request({
    url: "/api/trio-system/menu/buttons",
    method: "get",
  });

export const getAPK = () =>
  request({
    url: "/api/trio-system/minio/attach/selectAttachList",
    method: "post",
    data: {
      bucketName: "mes-frontend",
      extension: "apk",
    },
  });

export const refreshToken = (refresh_token, tenantId, deptId, roleId) =>
  request({
    url: "/api/trio-auth/oauth/token",
    method: "post",
    headers: {
      "Tenant-Id": tenantId,
      "Dept-Id": website.switchMode ? deptId : "",
      "Role-Id": website.switchMode ? roleId : "",
    },
    params: {
      tenantId,
      refresh_token,
      grant_type: "refresh_token",
      scope: "all",
    },
  });

export const logout = () =>
  request({
    url: "/api/trio-auth/oauth/logout",
    method: "get",
    authorization: false,
  });
